<?php

class Model_Village extends Base_Model
{
    protected $_tableName = 'Table_Village';
    
	protected $_fields = array(
			'aid','vid','sid','user','name','area','population','popu_women','popu_flow', 'master','intro'
		);

	
	public function readByUser()
	{
        $result = $this->getDbTable()
                    ->readBy('user', Base_Auth::getName());
        if (!$result) {
            throw new Base_Model_Exception(
               'You not have village permission', 404
            );
        }
        
        $this->setEntry($result);
        return $this;
	}

    protected function filterSid()
    {
        if ($this->vid) {
            $this->vid = $this->getStreet()->sid*100 +$this->vid;
        }
    }
    
    public function getStreet()
    {
        if (!$this->issetProperty('street')) {
            $street = new Model_Street();
            $street->read($this->sid);
            $this->setProperty('street', $street);
        }
        
        return $this->getProperty('street');
    }
}
